Crate keccak_const

source ·
Expand description

const fn implementation of the SHA-3 family of hash and extendable-output functions.

This crate allows you to use the SHA-3 hash and extendable-output functions as constant expressions in Rust. For all other usages, the sha3 crate includes more optimized implementations of these hash functions.

Examples

const PSEUDO_RANDOM_BYTES: [u8; 1000] = Shake256::new()
        .update(b"The quick brown fox ")
        .update(b"jumps over the lazy dog")
        .finalize();
const ROUND_CONSTANTS: [u128; 8] = {
    let shake = Shake128::new()
        .update(b"The quick brown fox ")
        .update(b"jumps over the lazy dog");

    let mut reader = shake.finalize_xof();
    let mut output = [0; 8];

    let mut i = 0;
    while i < 8 {
        let buf: [u8; 16];
        (reader, buf) = reader.read();
        output[i] = u128::from_be_bytes(buf);
        i += 1;
    }

    output
};

assert_eq!(
    [
        324498722242859095401832112442782838951,
        100470442341479765851591908475476895342,
        241049111671168257801898223573666863059,
        139197826094415251816510671569090212218,
        73371475849610774600276735485442220492,
        321031806373587100556524628628207173306,
        70553598458795679727810425741185559539,
        297273966300911440566694043047331846682,
    ],
    ROUND_CONSTANTS,
);

Structs